package com.syj.collect.Present;

import android.util.Log;

import com.google.gson.Gson;
import com.syj.collect.base.BasePresent;
import com.syj.collect.entry.MyPhone;
import com.syj.collect.entry.Mymonth;
import com.syj.collect.entry.UserInfoBean;
import com.syj.collect.http.BaseObserver;
import com.syj.collect.http.BaseRequest;
import com.syj.collect.utils.SPUtil;
import com.syj.collect.view.MonthActivityView;
import com.syj.collect.view.UserActivityView;

import java.util.HashMap;

import io.reactivex.android.schedulers.AndroidSchedulers;
import io.reactivex.schedulers.Schedulers;
import okhttp3.MediaType;
import okhttp3.RequestBody;

public class MonthPresent extends BasePresent<MonthActivityView> {
    public void getDataList(){

        HashMap hashMap = new HashMap();
        hashMap.put("token", SPUtil.getPrefString("token", ""));//可选
        Gson gson = new Gson();
        String str = gson.toJson(hashMap);
        RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"), str);



        BaseRequest.getInstance().getApiServise().getHistoryReport(body)
                .subscribeOn(Schedulers.io())
                .observeOn(AndroidSchedulers.mainThread())
                .subscribe(new BaseObserver<String>() {
                    @Override
                    public boolean onSuccess(String value) {
                        Gson json=new Gson();

                        Mymonth result = json.fromJson(value, Mymonth.class);
                        // JSONObject jsonObject = new JSONObject(value);
//                        Log.e("tag结果 :", value);
                        // JSONArray msg = jsonObject.getJSONArray("data");
                        int code = result.getCode();
                        if (code == 0) {
                            if (result.getData()!=null){

                                view.initsuccess(result.getData().getList());
                            }
                        } else {
                            view.initfail();
                        }

                        return false;
                    }

                    @Override
                    public void onFailure(Throwable e) throws Exception {

                    }

                    @Override
                    public void onEnd() {

                    }
                });






    }
}
